﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZK.Common.ProModels;

namespace ZK.Common
{
    /// <summary>
    /// 地磅磅单打印类
    /// </summary>
    public class ScalesPrint
    {
        #region 属性
        /// <summary>
        /// 运费
        /// </summary>
        public string YF;
        /// <summary>
        /// 打印的车辆信息
        /// </summary>
        public TruckYxInfo TruckYxInfo = new TruckYxInfo();
        /// <summary>
        /// 公司名称
        /// </summary>
        public string GSMC = "";
        /// <summary>
        /// 纸张宽度单位毫米
        /// </summary>
        private int width_p = 210;
        /// <summary>
        /// 纸张高度 单位毫米
        /// </summary>
        private int height_p = 93;
        /// <summary>
        /// 页面左右边距 单位毫米
        /// </summary>
        private int margin_lr = 2;
        /// <summary>
        /// 页面上下边距 单位毫米
        /// </summary>
        private int margin_tb = 2;
        /// <summary>
        /// 上下居中，左右居中
        /// </summary>
        private StringFormat stringFormatCenterAll = new StringFormat()
        {
            Alignment = StringAlignment.Center,
            LineAlignment = StringAlignment.Center
        };
        /// <summary>
        /// 左对齐
        /// </summary>
        private StringFormat stringFormatCenterLeft = new StringFormat()
        {
            Alignment = StringAlignment.Near,
            LineAlignment = StringAlignment.Center
        };
        /// <summary>
        /// 右对齐
        /// </summary>
        private StringFormat stringFormatCenterRight = new StringFormat()
        {
            Alignment = StringAlignment.Far,
            LineAlignment = StringAlignment.Center
        };
        /// <summary>
        /// 上对齐
        /// </summary>
        private StringFormat stringFormatCenterUp = new StringFormat()
        {
            Alignment = StringAlignment.Center,
            LineAlignment = StringAlignment.Near
        };/// <summary>
          /// 下对齐
          /// </summary>
        private StringFormat stringFormatCenterDown = new StringFormat()
        {
            Alignment = StringAlignment.Center,
            LineAlignment = StringAlignment.Far
        };
        #endregion
        public enum ScalesType
        {
            /// <summary>
            /// 出厂单
            /// </summary>
            printOut = 1,
            /// <summary>
            /// 出厂单(不需要时间)
            /// </summary>
            printOutNotime = 2,
            /// <summary>
            /// 入场单
            /// </summary>
            PrintIn = 0
        }
        /// <summary>
        /// 转换毫米到百分之一英寸
        /// </summary>
        /// <param name="mm"></param>
        /// <returns></returns>
        private int MM2Inch(double mm)
        {
            return (int)(mm * 100.0f / 25.4f);
        }
        /// <summary>
        /// 打印纸张的初始化
        /// </summary>
        /// <returns></returns>
        public PrintDocument printDocument(ScalesType scalesType)
        {
            try
            {
                System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
                pd.PrinterSettings.PrinterName = AppConfigHelper.GetAppSettings("printName");
                pd.DocumentName = pd.PrinterSettings.MaximumCopies.ToString();
                //磅单页面选择
                switch (scalesType)
                {
                    case ScalesType.printOut:
                        pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.PrintPageOut);
                        break;
                    case ScalesType.PrintIn:
                        pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.PrintPageIn);
                        break;
                    case ScalesType.printOutNotime:
                        pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.PrintPageOutNoTime);
                        break;
                    default:
                        break;
                }

                PrinterSettings printSetting = new PrinterSettings();
                printSetting.PrintRange = PrintRange.AllPages;
                int width_in = MM2Inch(width_p);
                int height_in = MM2Inch(height_p);
                PageSettings pageSetting = new PageSettings(printSetting);
                pageSetting.PaperSize = new PaperSize("customer", width_in, height_in);
                int margin_lr_in = MM2Inch(margin_lr);
                int margin_tb_in = MM2Inch(margin_tb);
                pageSetting.Margins = new Margins(margin_lr_in, margin_lr_in, margin_tb_in, margin_tb_in);
                pd.DefaultPageSettings = pageSetting;
                pd.PrintController = new System.Drawing.Printing.StandardPrintController();
                return pd;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 出厂磅单设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ev"></param>
        private void PrintPageOut(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
        {
            if (TruckYxInfo == null) TruckYxInfo = new TruckYxInfo();
            StringFormat stringFormatTitle = new StringFormat();
            stringFormatTitle.Alignment = StringAlignment.Center; //居中
            ev.Graphics.DrawString(GSMC, new Font("宋体", MM2Inch(5)), Brushes.Black, new Rectangle(MM2Inch(0), MM2Inch(16), MM2Inch(210), MM2Inch(90)), stringFormatTitle);//写字
            ev.Graphics.DrawString("日期：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "                No: " + TruckYxInfo.wbCode,
                new Font("宋体", MM2Inch(3)),
                Brushes.Black,
                new Rectangle(MM2Inch(0), MM2Inch(26), MM2Inch(210), MM2Inch(90)),
                stringFormatTitle
                );//写字


            double HBJ = 9;//行距
            double SXJL = 70;//列距
            StringFormat stringFormatBGZ = new StringFormat();//表格中字体格式
            stringFormatBGZ.Alignment = StringAlignment.Near; //水平
            stringFormatBGZ.LineAlignment = StringAlignment.Center;//垂直
            StringFormat stringFormatBGZ2 = new StringFormat();//表格中字体格式
            stringFormatBGZ2.Alignment = StringAlignment.Center; //水平
            stringFormatBGZ2.LineAlignment = StringAlignment.Center;//垂直

            for (int i = 1; i <= 5; i++)
            {
                string name1 = "";
                string name2 = "";

                switch (i)
                {

                    case 1:
                        name1 = "收货单位-" + TruckYxInfo.receivingPartyName;
                        name2 = "供货单位-" + TruckYxInfo.shipperName;
                        break;
                    case 2:
                        name1 = "";
                        name2 = "车    号-" + TruckYxInfo.truckNo;
                        break;
                    case 3:
                        name1 = "毛重-皮重-净重";
                        name2 = "";
                        break;
                    case 4:
                        name1 = "" + TruckYxInfo.mz * 1000 + "kg-" + TruckYxInfo.pz * 1000 + "kg-" + TruckYxInfo.jz * 1000 + "kg";
                        name2 = "";
                        break;
                    case 5:
                        name1 = "司磅员-" + AppSession.UserInfo.UserName + "-司机签名";
                        name2 = "";
                        break;

                    default:
                        break;
                }
                if (i == 3 || i == 4)
                {
                    var name34Arr = name1.Split('-');
                    if (name34Arr.Length > 0)
                    {
                        double JJ = 50;
                        for (int i34 = 0; i34 < name34Arr.Length; i34++)
                        {
                            ev.Graphics.DrawString(
                                 name34Arr[i34],
                                 new Font("宋体", MM2Inch(3.5)),
                                 Brushes.Black,
                                 new Rectangle(MM2Inch(42 + JJ * i34), MM2Inch((HBJ * i) + 21.5), MM2Inch(25), MM2Inch(9)),
                                stringFormatCenterAll
                               );
                        }
                    }

                }
                else if (i == 5)
                {
                    var name5Arr = name1.Split('-');
                    if (name5Arr.Length > 0)
                    {
                        double JJ = 25;
                        for (int i5 = 0; i5 < name5Arr.Length; i5++)
                        {
                            ev.Graphics.DrawString(
                              name5Arr[i5], new Font("宋体",
                              MM2Inch(3.5)),
                              Brushes.Black,
                              new Rectangle(MM2Inch(80 + i5 * JJ), MM2Inch((HBJ * i) + 21.5), MM2Inch(25), MM2Inch(9)),
                              stringFormatCenterAll
                              );//第一列字
                        }
                    }
                }
                else
                {
                    {
                        var name1Arr = name1.Split('-');
                        if (name1Arr.Length > 0)
                        {
                            for (int i1 = 0; i1 < name1Arr.Length; i1++)
                            {
                                switch (i1)
                                {
                                    case 0:
                                        ev.Graphics.DrawString(name1Arr[i1], new Font("宋体", MM2Inch(3.5)), Brushes.Black, new Rectangle(MM2Inch(28), MM2Inch((HBJ * i) + 21.5), MM2Inch(25), MM2Inch(9)),
                                            stringFormatCenterAll);//第二列字
                                        break;
                                    case 1:
                                        double areaW = 50;
                                        double fontSize = 3.5;
                                        int HZCount = name1Arr[i1].Length;
                                        if ((areaW / HZCount) < 5)
                                        {
                                            fontSize = 2.6;
                                        }
                                        ev.Graphics.DrawString(name1Arr[i1], new Font("宋体", MM2Inch(fontSize)), Brushes.Black, new Rectangle(MM2Inch(50), MM2Inch((HBJ * i) + 21.5), MM2Inch(areaW), MM2Inch(9)),
                                           stringFormatCenterAll);//第二列字
                                        break;
                                    default:
                                        break;
                                }
                            }

                        }
                    }
                    //var name2Arr = name2.Split('-');
                    //ev.Graphics.DrawString(name1, new Font("宋体", MM2Inch(3.5)), Brushes.Black, new Rectangle(MM2Inch(30.3), MM2Inch((HBJ * i) + 22.8), MM2Inch(75), MM2Inch(9)), stringFormatBGZ);//第一列字
                }
                //横向分区
                var name2Arr = name2.Split('-');
                if (name2Arr.Length > 0)
                {
                    for (int i1 = 0; i1 < name2Arr.Length; i1++)
                    {
                        switch (i1)
                        {
                            case 0:
                                ev.Graphics.DrawString(name2Arr[i1], new Font("宋体", MM2Inch(3.8)), Brushes.Black, new Rectangle(MM2Inch(97.3), MM2Inch((HBJ * i) + 21.5), MM2Inch(25), MM2Inch(9)),
                                   stringFormatCenterAll);//第二列字
                                break;
                            case 1:
                                double areaW = 60;
                                double fontSize = 3.5;
                                int HZCount = name2Arr[i1].Length;
                                if ((areaW / HZCount) < 5)
                                {
                                    fontSize = 2.6;
                                }
                                ev.Graphics.DrawString(name2Arr[i1], new Font("宋体", MM2Inch(fontSize)), Brushes.Black, new Rectangle(MM2Inch(120.3), MM2Inch((HBJ * i) + 21.5), MM2Inch(areaW), MM2Inch(9)),
                                   stringFormatCenterAll);//第二列字
                                break;
                            default:
                                break;
                        }
                    }

                }
                //划线
                ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(30), MM2Inch((HBJ * i) + 30), MM2Inch(180), MM2Inch(30 + (HBJ * i)));//横线




            }

            for (int i = 0; i < 2; i++)
            {

                ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(50 + SXJL * i), MM2Inch(30), MM2Inch(50 + SXJL * i), MM2Inch(48));//中线两边

            }
            ev.Graphics.DrawRectangle(new Pen(Brushes.Black, 1), new Rectangle(MM2Inch(30), MM2Inch(30), MM2Inch(150), MM2Inch(45)));//矩形
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(100), MM2Inch(30), MM2Inch(100), MM2Inch(48));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(100), MM2Inch(30), MM2Inch(100), MM2Inch(48));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(80), MM2Inch(48), MM2Inch(80), MM2Inch(75));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(130), MM2Inch(48), MM2Inch(130), MM2Inch(75));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(105), MM2Inch(66), MM2Inch(105), MM2Inch(75));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(155), MM2Inch(66), MM2Inch(155), MM2Inch(75));//中线

        }
        /// <summary>
        /// 出厂磅单设置(没时间)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ev"></param>
        private void PrintPageOutNoTime(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
        {
            if (TruckYxInfo == null) TruckYxInfo = new TruckYxInfo();
            StringFormat stringFormatTitle = new StringFormat();
            stringFormatTitle.Alignment = StringAlignment.Center; //居中
            ev.Graphics.DrawString(GSMC, new Font("宋体", MM2Inch(5)), Brushes.Black, new Rectangle(MM2Inch(0), MM2Inch(16), MM2Inch(210), MM2Inch(90)), stringFormatTitle);//写字
            ev.Graphics.DrawString("日期：                                  No: " + TruckYxInfo.wbCode,
                new Font("宋体", MM2Inch(3)),
                Brushes.Black,
                new Rectangle(MM2Inch(0), MM2Inch(26), MM2Inch(210), MM2Inch(90)),
                stringFormatTitle
                );//写字



            double HBJ = 9;//行距
            double SXJL = 70;//列距



            for (int i = 1; i <= 5; i++)
            {
                string name1 = "";
                string name2 = "";

                switch (i)
                {

                    case 1:
                        name1 = "收货单位-" + TruckYxInfo.receivingPartyName;
                        name2 = "供货单位-" + TruckYxInfo.shipperName;
                        break;
                    case 2:
                        name1 = "";
                        name2 = "车    号-" + TruckYxInfo.truckNo;
                        break;
                    case 3:
                        name1 = "毛重-皮重-净重";
                        name2 = "";
                        break;
                    case 4:
                        name1 = "" + TruckYxInfo.mz * 1000 + "kg-" + TruckYxInfo.pz * 1000 + "kg-" + TruckYxInfo.jz * 1000 + "kg";
                        name2 = "";
                        break;
                    case 5:
                        name1 = "司磅员-" + AppSession.UserInfo.UserName + "-司机签名";
                        name2 = "";
                        break;

                    default:
                        break;
                }
                if (i == 3 || i == 4)
                {
                    var name34Arr = name1.Split('-');
                    if (name34Arr.Length > 0)
                    {
                        double JJ = 50;
                        for (int i34 = 0; i34 < name34Arr.Length; i34++)
                        {
                            ev.Graphics.DrawString(
                                 name34Arr[i34],
                                 new Font("宋体", MM2Inch(3.5)),
                                 Brushes.Black,
                                 new Rectangle(MM2Inch(42 + JJ * i34), MM2Inch((HBJ * i) + 21.5), MM2Inch(25), MM2Inch(9)),
                                stringFormatCenterAll
                               );
                        }
                    }

                }
                else if (i == 5)
                {
                    var name5Arr = name1.Split('-');
                    if (name5Arr.Length > 0)
                    {
                        double JJ = 25;
                        for (int i5 = 0; i5 < name5Arr.Length; i5++)
                        {
                            ev.Graphics.DrawString(
                              name5Arr[i5], new Font("宋体",
                              MM2Inch(3.5)),
                              Brushes.Black,
                              new Rectangle(MM2Inch(80 + i5 * JJ), MM2Inch((HBJ * i) + 21.5), MM2Inch(25), MM2Inch(9)),
                              stringFormatCenterAll
                              );//第一列字
                        }
                    }
                }
                else
                {
                    {
                        var name1Arr = name1.Split('-');
                        if (name1Arr.Length > 0)
                        {
                            for (int i1 = 0; i1 < name1Arr.Length; i1++)
                            {
                                switch (i1)
                                {
                                    case 0:
                                        ev.Graphics.DrawString(name1Arr[i1], new Font("宋体", MM2Inch(3.5)), Brushes.Black, new Rectangle(MM2Inch(28), MM2Inch((HBJ * i) + 21.5), MM2Inch(25), MM2Inch(9)),
                                          stringFormatCenterAll
                                            );//第二列字
                                        break;
                                    case 1:
                                        double areaW = 50;
                                        double fontSize = 3.5;
                                        int HZCount = name1Arr[i1].Length;
                                        if ((areaW / HZCount) < 5)
                                        {
                                            fontSize = 2.6;
                                        }
                                        ev.Graphics.DrawString(name1Arr[i1], new Font("宋体", MM2Inch(fontSize)), Brushes.Black, new Rectangle(MM2Inch(50), MM2Inch((HBJ * i) + 21.5), MM2Inch(areaW), MM2Inch(9)),
                                           stringFormatCenterAll
                                           );//第二列字
                                        break;
                                    default:
                                        break;
                                }
                            }

                        }
                    }
                    //var name2Arr = name2.Split('-');
                    //ev.Graphics.DrawString(name1, new Font("宋体", MM2Inch(3.5)), Brushes.Black, new Rectangle(MM2Inch(30.3), MM2Inch((HBJ * i) + 22.8), MM2Inch(75), MM2Inch(9)), stringFormatBGZ);//第一列字
                }
                //横向分区
                var name2Arr = name2.Split('-');
                if (name2Arr.Length > 0)
                {
                    for (int i1 = 0; i1 < name2Arr.Length; i1++)
                    {
                        switch (i1)
                        {
                            case 0:
                                ev.Graphics.DrawString(name2Arr[i1], new Font("宋体", MM2Inch(3.8)), Brushes.Black, new Rectangle(MM2Inch(97.3), MM2Inch((HBJ * i) + 21.5), MM2Inch(25), MM2Inch(9)),
                                   stringFormatCenterAll);//第二列字
                                break;
                            case 1:
                                double areaW = 60;
                                double fontSize = 3.5;
                                int HZCount = name2Arr[i1].Length;
                                if ((areaW / HZCount) < 5)
                                {
                                    fontSize = 2.6;
                                }
                                ev.Graphics.DrawString(name2Arr[i1], new Font("宋体", MM2Inch(fontSize)), Brushes.Black, new Rectangle(MM2Inch(120.3), MM2Inch((HBJ * i) + 21.5), MM2Inch(areaW), MM2Inch(9)),
                                stringFormatCenterAll);//第二列字
                                break;
                            default:
                                break;
                        }
                    }

                }
                //划线
                ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(30), MM2Inch((HBJ * i) + 30), MM2Inch(180), MM2Inch(30 + (HBJ * i)));//横线




            }

            for (int i = 0; i < 2; i++)
            {

                ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(50 + SXJL * i), MM2Inch(30), MM2Inch(50 + SXJL * i), MM2Inch(48));//中线两边

            }
            ev.Graphics.DrawRectangle(new Pen(Brushes.Black, 1), new Rectangle(MM2Inch(30), MM2Inch(30), MM2Inch(150), MM2Inch(45)));//矩形
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(100), MM2Inch(30), MM2Inch(100), MM2Inch(48));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(100), MM2Inch(30), MM2Inch(100), MM2Inch(48));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(80), MM2Inch(48), MM2Inch(80), MM2Inch(75));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(130), MM2Inch(48), MM2Inch(130), MM2Inch(75));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(105), MM2Inch(66), MM2Inch(105), MM2Inch(75));//中线
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(155), MM2Inch(66), MM2Inch(155), MM2Inch(75));//中线

        }

        /// <summary>
        /// 入厂磅单设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ev"></param>
        private void PrintPageIn(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
        {
            if (TruckYxInfo == null) TruckYxInfo = new TruckYxInfo();
            StringFormat stringFormatTitle = new StringFormat();
            stringFormatTitle.Alignment = StringAlignment.Center; //居中
            ev.Graphics.DrawString(GSMC, new Font("宋体", MM2Inch(5)), Brushes.Black, new Rectangle(MM2Inch(0), MM2Inch(16), MM2Inch(210), MM2Inch(90)), stringFormatTitle);//写字
            ev.Graphics.DrawString("日期：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "                No: " + TruckYxInfo.wbCode, new Font("宋体", MM2Inch(3)), Brushes.Black, new Rectangle(MM2Inch(0), MM2Inch(26), MM2Inch(210), MM2Inch(90)), stringFormatTitle);//写字
            double HBJ = 7.5;//行边距
            double SXJL = 70;//列距
            StringFormat stringFormatBGZ = new StringFormat();//表格中字体格式
            stringFormatBGZ.Alignment = StringAlignment.Near; //水平
            stringFormatBGZ.LineAlignment = StringAlignment.Center;//垂直

            for (int i = 1; i <= 6; i++)
            {
                string name1 = "";
                string name2 = "";
                switch (i)
                {

                    case 1:
                        name1 = "矿    发-" + TruckYxInfo.coalmineOutput * 1000 + "kg";
                        name2 = "车    号-" + TruckYxInfo.truckNo;
                        break;
                    case 2:
                        name1 = "扣    重-" + TruckYxInfo.buckleWeight * 1000 + "kg";
                        name2 = "毛    重-" + TruckYxInfo.mz * 1000 + "kg";
                        break;
                    case 3:
                        name1 = "供货单位-" + TruckYxInfo.shipperName + "【" + TruckYxInfo.coalName + "】";
                        name2 = "皮    重-" + TruckYxInfo.pz * 1000 + "kg";
                        break;
                    case 4:
                        name1 = "收货单位-" + TruckYxInfo.receivingPartyName;
                        name2 = "实收净重-" + TruckYxInfo.jz * 1000 + "kg";
                        break;
                    case 5:
                        name1 = "司 磅 员-" + AppSession.UserInfo.UserName;
                        name2 = "收 煤 人-";
                        break;
                    case 6:
                        name1 = "运    费-" + YF + " 元/吨";
                        name2 = "备    注-";
                        break;
                    default:
                        break;
                }
                var name1Arr = name1.Split('-');
                if (name1Arr.Length > 0)
                {
                    double JJ = 22;
                    for (int i1 = 0; i1 < name1Arr.Length; i1++)
                    {
                        if (i1 == 0)
                        {
                            ev.Graphics.DrawString(
                           name1Arr[i1],
                           new Font("宋体", MM2Inch(3.5)),
                           Brushes.Black,
                           new Rectangle(MM2Inch(27.5 + i1 * JJ), MM2Inch((HBJ * i) + 23.0), MM2Inch(25), MM2Inch(7.5)),
                           new StringFormat()
                           {
                               Alignment = StringAlignment.Center,
                               LineAlignment = StringAlignment.Center
                           }
                           );//第一列字
                        }
                        else if (i1 == 1)
                        {
                            double areaW = 51;
                            double fontSize = 3.5;
                            int wordNum = name1Arr[i1].Length;
                            if (areaW / wordNum < 5.1)
                            {
                                fontSize = 2.5;
                            }

                            ev.Graphics.DrawString(
                           name1Arr[i1],
                           new Font("宋体", MM2Inch(fontSize)),
                           Brushes.Black,
                           new Rectangle(MM2Inch(49.5), MM2Inch((HBJ * i) + 22.8), MM2Inch(51), MM2Inch(8)),
                          stringFormatCenterAll
                           );//第一列字
                        }

                    }
                }
                var name2Arr = name2.Split('-');
                if (name2Arr.Length > 0)
                {
                    double rowSpacing = 25;
                    for (int i2 = 0; i2 < name2Arr.Length; i2++)
                    {
                        switch (i2)
                        {
                            //左边列名
                            case 0:
                                ev.Graphics.DrawString(
                           name2Arr[i2],
                           new Font("宋体", MM2Inch(3.5)),
                           Brushes.Black, new Rectangle(MM2Inch(99.3 + i2 * rowSpacing), MM2Inch((HBJ * i) + 23.5), MM2Inch(22), MM2Inch(7.5)),
                          stringFormatCenterAll
                           );
                                break;
                            //右边内容
                            case 1:
                                ev.Graphics.DrawString(
                           name2Arr[i2],
                           new Font("宋体", MM2Inch(3.5)),
                           Brushes.Black, new Rectangle(MM2Inch(95 + i2 * rowSpacing), MM2Inch((HBJ * i) + 23.5), MM2Inch(60), MM2Inch(7.5)),
                           stringFormatCenterAll
                           );//第二列字
                                break;
                            default:
                                break;
                        }

                    }
                }

                if (i < 6) ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(30), MM2Inch((HBJ * i) + 30), MM2Inch(180), MM2Inch(30 + (HBJ * i)));//横线
            }
            for (int i = 0; i < 2; i++)
            {

                ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(50 + SXJL * i), MM2Inch(30), MM2Inch(50 + SXJL * i), MM2Inch(75));//中线

            }
            ev.Graphics.DrawRectangle(new Pen(Brushes.Black, 1), new Rectangle(MM2Inch(30), MM2Inch(30), MM2Inch(150), MM2Inch(45)));//矩形
            ev.Graphics.DrawLine(new Pen(Brushes.Black, 1), MM2Inch(100), MM2Inch(30), MM2Inch(100), MM2Inch(75));//中线
        }
    }
}
